<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title></title>
    <link rel="stylesheet" href="{$Assets}layui/css/layui.css">
    <style type="text/css">
.layui-table-body{
    overflow: hidden;
}
    </style>
</head>
<body>
{include file="public/header" /}
<div class="layui-btn-group demoTable" style="margin-left: 15px;">
    <button class="layui-btn" data-type="addshop">添加商品</button>
    <button class="layui-btn layui-btn-danger" data-type="delshops">删除选中</button>
</div>


<div style="width: 98%;margin:0 auto;">
<table class="layui-hide" id="LAY_table_user" lay-filter="user"></table> 
</div>

<script type="text/html" id="motion">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script src="{$Assets}layui/layui.js?t=1515376178709"></script>
<script>
layui.use('table', function(){
  var table = layui.table;
  
  //
  table.render({
    elem: '#LAY_table_user'
    ,url: 'allshops'
    ,cols: [[
      {checkbox: true, fixed: true}
      ,{field:'id', title: 'ID', width:80, sort: true, fixed: true}
      ,{field:'title', title: '标题'}
      ,{field:'num', title: '库存',  width:80}
      ,{field:'pay', title: '积分', width:80}
      ,{fixed: 'right', width:178, align:'center', toolbar: '#motion'}
    ]]
    ,id: 'prolist'
    ,page: true
 
  });
  //
  table.on('checkbox(user)', function(obj){
    console.log(obj)
  });

  //
  table.on('tool(user)', function(obj){
    var data = obj.data;
    if(obj.event === 'edit'){
      //layer.msg('ID+ data.id + ' );


      //
      layer.open({
        type: 2 //iframe
        ,title: '编辑商品'
        ,area: ['50%', '90%']
        ,shade: 0.8

        ,maxmin: true
        ,offset: 'auto'
        ,content: "{:url('integral/editshop')}?id="+data.id
        ,zIndex: layer.zIndex //1
        ,success: function(layero){
          layer.setTop(layero); //2
        }
      });


    } else if(obj.event === 'del'){
      layer.confirm('', function(index){


                  $.ajax({
                        type:"POST",
                        url: "{:url('integral/delshop')}",
                        data:{data:data.id},
                        dataType:"json",

                        success:function(ret_datas){
                            if(ret_datas==1){
                                layer.msg('删除成功!');
                            }else if(ret_datas==99){
                                layer.msg('删除异常');
                            }else{
                                layer.msg(ret_datas);
                            }
                            
                        }
                    });



        obj.del();
        setTimeout(function(){
            location.reload();
        },"1000");
        
      });
    }
  });

  var $ = layui.$, active = {
    reload: function(){
      var demoReload = $('#prolist');
      
      //
      table.reload('testReload', {
        page: {
          curr: 1 // 1 
        }
        ,where: {
          key: {
            id: demoReload.val()
          }
        }
      });
    },
    delshops: function(){ //
      var checkStatus = table.checkStatus('prolist')
      ,data = checkStatus.data;
      delspro=JSON.stringify(data);

                  $.ajax({
                        type:"POST",
                        url: "{:url('integral/delshops')}",
                        data:{data:delspro},
                        dataType:"json",

                        success:function(ret_datas){
                            if(ret_datas==1){
                                layer.msg('删除成功！');
                            }else if(ret_datas==99){
                                layer.msg('删除异常！');
                            }else{
                                layer.msg(ret_datas);
                            }
                            setTimeout("location.reload();",1000);
                        }
                    });


    },
    addshop:function(){
      //
      layer.open({
        type: 2 //iframe
        ,title: '添加商品'
        ,area: ['50%', '90%']
        ,shade: 0.8

        ,maxmin: true
        ,offset: 'auto'
        ,content: "{:url('integral/addshop')}"
        ,zIndex: layer.zIndex //1
        ,success: function(layero){
          layer.setTop(layero); //2
        }
      });
    },

  };
  
  $('.demoTable .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
});
</script>

{include file="public/footer"/}
</body>
</html>